package com.longyiqun.apitest;


import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.KlovReporter;
import com.aventstack.extentreports.reporter.configuration.ChartLocation;
import com.aventstack.extentreports.reporter.configuration.Theme;

/**
 * program: ApiTest
 * package: com.longyiqun.apitest
 * author: 龙轶群
 * create: 2018-04-16 11:11
 **/

public class ExtentManager {

    private static ExtentReports extent;

    public static ExtentReports getInstance() {
        if (extent == null)
            createInstance("test-output/extent-api.html");

        return extent;
    }

    public static ExtentReports createInstance(String fileName) {

        // HTML Report
        ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(fileName);
        htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
        htmlReporter.config().setChartVisibilityOnOpen(true);
        htmlReporter.config().setTheme(Theme.STANDARD);
        htmlReporter.config().setDocumentTitle(fileName);
        htmlReporter.config().setEncoding("utf-8");
        htmlReporter.config().setReportName("API测试报告");

        extent = new ExtentReports();

        // KLOV Report
        KlovReporter klov = new KlovReporter();
        klov.initMongoDbConnection(Constants.ReportServer, Constants.ReportPort);
        klov.setProjectName(Constants.KlovProjectName);
        klov.setReportName(Constants.KlovReportName);
        klov.setKlovUrl(Constants.KlovUrl);

        extent.attachReporter(htmlReporter, klov);

        return extent;
    }

//    public static ExtentXReporter createExtentXReporter() {
//        ExtentXReporter extentx = new ExtentXReporter(Constants.ReportServer,Constants.ReportPort);
//        extentx.config().setProjectName("YppAPI");
//        extentx.config().setReportName("YPP-API测试报告");
//        extentx.config().setServerUrl(Constants.ReportURL);
//        return extentx;
//    }
}
